package java5.genericity.container;

import java.util.*;

public class Favorites {

    private Map<Class<?>, Object> favorites = new HashMap<>();

    public <T> void putFavorite(Class<T> type, T instance) {
        favorites.put(Objects.requireNonNull(type), type.cast(instance));
    }

    public <T> T getFavorite(Class<T> type) {
        return type.cast(favorites.get(type));
    }

    public static void main(String[] args) {

        Favorites f = new Favorites();

        //原生态使用class

/*        Class classString=String.class;//类
        Class classEnum=RetentionPolicy.class;//枚举
        Class classInterface=Serializable.class;//接口
        Class classAnnotation=Retention.class;//注解
        Class classInt=int.class;//原生类型
        Class classIntArray=int[].class;//原生数组类型
        Class classStringArray=String[].class;//数组类型*/

        Set set = new HashSet<Integer>();
        set.add("abc");
        set.add(1);

        f.putFavorite(Collection.class,set);
        f.putFavorite(Object.class,1);

        System.out.println(f.getFavorite(Set.class));

        System.out.println(  System.getProperty("java.version"));

    }

}
